package com.benz.project.pvm.service;

import com.benz.project.pvm.domain.Person;
import com.benz.project.pvm.repository.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class PersonService {

    @Autowired
    private PersonRepository personRepository;

    /**
     * 新增人员
     * @param name
     * @param phone
     * @param mail
     * @param projectId
     * @param roleId
     */
    public void addPerson(String name,
                                String phone,
                                String mail){
        Person person = new Person();
        person.setId(UUID.randomUUID().toString());
        person.setName(name);
        person.setPhone(phone);
        person.setMail(mail);
        personRepository.save(person);
    }

    /**
     * 修改人员
     * @param id
     * @param name
     * @param phone
     * @param mail
     * @param projectId
     * @param roleId
     */
    public void updatePerson(String id,
                             String name,
                             String phone,
                             String mail){
        Person person = personRepository.getOne(id);
        person.setName(name);
        person.setPhone(phone);
        person.setMail(mail);
        personRepository.save(person);
    }

    /**
     * 删除人员
     * @param ids
     */
    public void deletePersons(String[] ids){
        for(String id : ids){
            personRepository.deleteById(id);
        }
    }

    /**
     * 获取单个人员信息
     * @param id
     * @return
     */
    public Person getPerson(String id){
        return personRepository.getOne(id);
    }

    /**
     * 获取所有人员信息
     * @return
     */
    public List<Person> getPersons(){
        return personRepository.findAll();
    }

}
